<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: royalblue;
        }
    </style>
</head>
<body>
    <div id="box" class="box"></div>

    <script>
        // 需求1：点击div 0.5s后背景色变成pink
        let box = document.getElementById('box');
        box.addEventListener('click', function() {
            /* let _this = this;
            setTimeout(function() {
                console.log(this); // this指向window
                _this.style.background = 'pink'
            }, 500); */

            setTimeout(() => {
                this.style.background = 'pink'
            }, 500);
        })

        // 需求2：从数组返回偶数的元素
        const data = [0, 1, 3, 2, 4, 7, 6, 9, 8];
        const result = data.filter(item => item % 2 === 0);
        console.log(result);

        /*
          总结：
            1. 箭头函数适合与this无关的回调，例如：定时器、数组的方法等
            2. 箭头函数不适合与this有关的回调，例如：事件的回调、对象内部方法等
        */
    </script>
</body>
</html>